﻿using AutoMapper;
using HamcoWcs.Entitys.SubTaskBaks;
using HamcoWcs.Entitys.SubTasks;
using HamcoWcs.Models.Common;
using HamcoWcs.Models.ForeEndModels.UITasks;
using System;

namespace HamcoWcs.Models.SubTasks
{
    public class SubTaskProfile : Profile
    {
        public SubTaskProfile()
        {
            CreateMap<SubTask, SubTaskDto>();
            CreateMap<SubTaskDto, SubTask>();
            CreateMap<SubTask, SubTaskBak>().ForMember(dest => dest.Id, opt => opt.Ignore());
            CreateMap<SubTask, UISubTask>()
                .ForMember(d => d.TransportTime, src => src.MapFrom(x =>
                x.CompleteTime == default(DateTime) ? "" : (x.CompleteTime - x.SendTime).GetDuration()
                ));

            CreateMap<SubTaskBak, UISubTask>()
                 .ForMember(d => d.TransportTime, src => src.MapFrom(x =>
                x.CompleteTime == default(DateTime) ? "" : (x.CompleteTime - x.SendTime).GetDuration()
                ));
            CreateMap<SubTaskBak, SubTask>();
            CreateMap<SubTaskDto, SubTaskBak>().ForMember(dest => dest.Id, opt => opt.Ignore()); ;
            CreateMap<SubTaskBak, SubTaskDto>();

            CreateMap<SubTask, UISrmSubTask>();

        }
    }
}
